//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package ciicos.visualdata.controller;

import ciicos.base.ActionResult;
import ciicos.base.controller.SuperController;
import ciicos.util.JsonUtil;
import ciicos.util.StringUtil;
import ciicos.visualdata.entity.VisualRecordEntity;
import ciicos.visualdata.model.VisualPageVO;
import ciicos.visualdata.model.VisualPagination;
import ciicos.visualdata.model.visualrecord.VisualRecordCrForm;
import ciicos.visualdata.model.visualrecord.VisualRecordInfoVO;
import ciicos.visualdata.model.visualrecord.VisualRecordListVO;
import ciicos.visualdata.model.visualrecord.VisualRecordUpForm;
import ciicos.visualdata.service.VisualRecordService;
import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Tag(
        name = "大屏数据集配置",
        description = "record"
)
@RequestMapping({"/api/blade-visual/record"})
public class VisualRecordController extends SuperController<VisualRecordService, VisualRecordEntity> {
    @Autowired
    private VisualRecordService recordService;

    @Operation(
            summary = "分页"
    )
    @GetMapping({"/list"})
    public ActionResult<VisualPageVO<VisualRecordListVO>> list(VisualPagination pagination) {
        List<VisualRecordEntity> data = this.recordService.getList(pagination);
        List<VisualRecordListVO> list = JsonUtil.getJsonToList(data, VisualRecordListVO.class);
        VisualPageVO paginationVO = (VisualPageVO)JsonUtil.getJsonToBean(pagination, VisualPageVO.class);
        paginationVO.setRecords(list);
        return ActionResult.success(paginationVO);
    }

    @Operation(
            summary = "详情"
    )
    @GetMapping({"/detail"})
    @Parameters({@Parameter(
            name = "id",
            description = "主键",
            required = true
    )})
    @SaCheckPermission({"onlineDev.dataScreen"})
    public ActionResult<VisualRecordInfoVO> info(@RequestParam("id") String id) {
        VisualRecordEntity entity = this.recordService.getInfo(id);
        VisualRecordInfoVO vo = (VisualRecordInfoVO)JsonUtil.getJsonToBean(entity, VisualRecordInfoVO.class);
        return ActionResult.success(vo);
    }

    @Operation(
            summary = "新增或修改"
    )
    @PostMapping({"/submit"})
    @Parameters({@Parameter(
            name = "recordUpForm",
            description = "数据模型",
            required = true
    )})
    @SaCheckPermission({"onlineDev.dataScreen"})
    public ActionResult submit(@RequestBody VisualRecordUpForm recordUpForm) {
        VisualRecordEntity entity = (VisualRecordEntity)JsonUtil.getJsonToBean(recordUpForm, VisualRecordEntity.class);
        if (StringUtil.isEmpty(entity.getId())) {
            this.recordService.create(entity);
            return ActionResult.success("新建成功");
        } else {
            this.recordService.update(entity.getId(), entity);
            return ActionResult.success("更新成功");
        }
    }

    @Operation(
            summary = "新增"
    )
    @PostMapping({"/save"})
    @Parameters({@Parameter(
            name = "recordCrForm",
            description = "数据模型",
            required = true
    )})
    @SaCheckPermission({"onlineDev.dataScreen"})
    public ActionResult create(@RequestBody VisualRecordCrForm recordCrForm) {
        VisualRecordEntity entity = (VisualRecordEntity)JsonUtil.getJsonToBean(recordCrForm, VisualRecordEntity.class);
        this.recordService.create(entity);
        return ActionResult.success("新建成功");
    }

    @Operation(
            summary = "修改"
    )
    @PostMapping({"/update"})
    @Parameters({@Parameter(
            name = "recordUpForm",
            description = "数据模型",
            required = true
    )})
    @SaCheckPermission({"onlineDev.dataScreen"})
    public ActionResult update(@RequestBody VisualRecordUpForm recordUpForm) {
        VisualRecordEntity entity = (VisualRecordEntity)JsonUtil.getJsonToBean(recordUpForm, VisualRecordEntity.class);
        this.recordService.update(entity.getId(), entity);
        return ActionResult.success("更新成功");
    }

    @Operation(
            summary = "删除"
    )
    @PostMapping({"/remove"})
    @Parameters({@Parameter(
            name = "ids",
            description = "主键",
            required = true
    )})
    @SaCheckPermission({"onlineDev.dataScreen"})
    public ActionResult delete(String ids) {
        VisualRecordEntity entity = this.recordService.getInfo(ids);
        if (entity != null) {
            this.recordService.delete(entity);
            return ActionResult.success("删除成功");
        } else {
            return ActionResult.fail("删除失败，数据不存在");
        }
    }
}
